import time

import matplotlib.pyplot as plt
from selenium import webdriver
from selenium.webdriver.common.by import By


options = webdriver.ChromeOptions()
#options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--window-size=1920x1080')


browser = webdriver.Chrome(options)
browser.get("https://www.xiaohongshu.com/user/profile/5acc23bbe8ac2b6a248ab88b")
# login_btn = browser.find_element(By.XPATH, '//*[@id="login-btn"]')
# login_btn.click()
# time.sleep(5)
# tele_number = browser.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[1]/div[3]/div[2]/form/label[1]/input')
# tele_number.send_keys('19818505782')
# yzm_btn = browser.find_element(By.XPATH,'//*[@id="app"]/div[1]/div/div[1]/div[3]/div[2]/form/label[2]/span')
# yzm_btn.click()
# time.sleep(2)
# yinsi_btn = browser.find_element(By.XPATH,'//*[@id="app"]/div[1]/div/div[1]/div[3]/div[3]/span/div')
# yinsi_btn.click()
# time.sleep(15)
# denglu_btn = browser.find_element(By.XPATH,'//*[@id="app"]/div[1]/div/div[1]/div[3]/div[2]/form/button')
# denglu_btn.click()
# time.sleep(5)
time.sleep(20)
for m in range(1,40):
    for i in range(1,28):
        element = browser.find_element(By.XPATH, f'//*[@id="userPostedFeeds"]/section[{i}]/div/a[1]').get_attribute('href')
        print(element)
        with open('urls.txt', 'w') as f:
            f.write(element + '\n')
    browser.execute_script(f'window.scrollTo(0,document.body.scrollHeight)')
    time.sleep(5)